document.addEventListener('DOMContentLoaded', function() {
    // 处理"显示更多"按钮
    const showMoreButtons = document.querySelectorAll('.show-more');
    showMoreButtons.forEach(button => {
        button.addEventListener('click', function() {
            const target = this.dataset.target;
            const categoryList = this.previousElementSibling;
            
            if (categoryList.classList.contains('collapsed')) {
                categoryList.classList.remove('collapsed');
                this.textContent = '收起';
            } else {
                categoryList.classList.add('collapsed');
                this.textContent = '显示更多';
            }
        });
    });

    // 初始化时折叠所有超过5个项目的列表
    const categoryLists = document.querySelectorAll('.category-list');
    categoryLists.forEach(list => {
        if (list.children.length > 5) {
            list.classList.add('collapsed');
        }
    });

    // 处理类目选择
    const categoryItems = document.querySelectorAll('.category-item');
    categoryItems.forEach(item => {
        item.addEventListener('click', function(e) {
            // 移除同级类目的选中状态
            const siblings = this.parentElement.querySelectorAll('.category-item');
            siblings.forEach(sibling => sibling.classList.remove('selected'));
            
            // 添加当前类目的选中状态
            this.classList.add('selected');
        });
    });
}); 